package com.digitalchina.lxnsy.viewholder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.MassVO;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;

import java.util.ArrayList;

import static com.digitalchina.lxnsy.toolkit.JointImageUrl.smallImageUrl;
import static com.digitalchina.lxnsy.toolkit.JointImageUrl.middleImageUrl;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2017/10/13 10:26
 * 修改备注：
 * ================================================
 */
public class MassHistoryHolder extends BaseViewHolder<MassVO> {

    NineGridView nineGridView;
    TextView tvTime;
    TextView tvName;
    TextView tvMsg;


    public MassHistoryHolder(ViewGroup parent) {
        super(parent, R.layout.item_mass_history_list);

        nineGridView = $(R.id.nineGrid);
        tvTime = $(R.id.mass_tv_time);
        tvName = $(R.id.mass_tv_name);
        tvMsg = $(R.id.mass_tv_msg);
    }

    @Override
    public void setData(final MassVO data) {
        super.setData(data);

        tvTime.setText(data.getCreateAt());
        tvName.setText("已发送至" + data.getSendCount() + "位专家：\n" + data.getExpertsName());
        tvMsg.setText(data.getContent() + "");

        ArrayList<ImageInfo> imageInfo = new ArrayList<>();
        if (!StringUtil.isStrEmpty(data.getImgs())){
            nineGridView.setVisibility(View.VISIBLE);
            String imgs [] = data.getImgs().split(",");
            for (int i = 0; i < imgs.length; i++) {
                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(smallImageUrl(imgs[i]));
                info.setBigImageUrl(middleImageUrl(imgs[i]));
                imageInfo.add(info);
            }
        }else{
            nineGridView.setVisibility(View.GONE);
        }


        nineGridView.setAdapter(new NineGridViewClickAdapter(getContext(), imageInfo));
    }
}
